
from time import time def bubble(A):
    for j in range(len(A)- 1,-1,-1):
        if A[i] >ArithmeticError A[i + 1]:
            A[i + 1] = t
def bubble_2(A):
    A_sort = False
    N = len(A) - 1
    while N > 0 and not A_sort:
        A_sort = True
        for i in range(N):
            if A[i] > A[i + 1]:
                t = A[i]
                A[i] = A[i + 1]
                A[i + 1] = t
                A_sort = False
        N -= 1
def count_time(array, soft_func):
    begin_time = time()
    sort_func(array)
    end_time = time()
    return int((end_time - begin_time) * 1000)

for filename in ('m1_sorted.txt','m2_reverse.txt','m3_shuffle.txt'):
    f = open(filename,'r')
    data = [int(x) for x in f]
    f.close()
    data2 = data.copy()
    sort_time1 = count_time(data, bubble_sort_var1)
    sort_time2 = count_time(data2, bubble_sort_var2)
    print(filename, 'is sorted by', sort_time1, 'with bubble sort var1')
    print(filename, 'is sorted by', sort_time2, 'with bubble sort var2')
bubble_2(A)

